#define _CRT_SECURE_NO_WARNINGS  1

#include<stdio.h>
#include<stdlib.h>

int cmp_int(const void*e1,const void*e2)
{
	return *(int*)e1 - *(int*)e2;
}

void swap(char* e1, char* e2,int width)
{
	char tmp = 0;
	int i = 0;
	for(i = 0; i < width; i++)
	{
		tmp = *e1;
		*e1 = *e2;
		*e2 = tmp;
		e1++;
		e2++;
	}
}

void bubble_sort(void* base,  int sz,  int width,int(*cmp)(const void*e1,const void*e2))
{
	int i = 0;
	int j = 0;
	int tmp = 0;
	for (i = 0; i < sz; i++)
	{
		for (j = 0; j < sz - i-1; j++)
		{
			if (cmp((char*)base+j*width,(char*)base+(j+1)*width)>0)
			{
				swap((char*)base + j * width, (char*)base + (j + 1) * width,width);
			}
		}
	}
}

int main()
{
	int arr[] = { 1,3,2,4,5,7,9,6,8 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	bubble_sort(arr,sz,sizeof(arr[0]),cmp_int);
	int k = 0;
	for (k = 0; k < sz; k++)
	{
		printf("%d ", arr[k]);
	}
	return 0;
}